package com.epam.lunch.service;

import static java.lang.String.format;

import java.util.ArrayList;
import java.util.List;

import com.epam.lunch.domain.Order;
import com.epam.lunch.domain.OrderItem;
import com.epam.lunch.ws.SimpleOrder;

public class NetCincer implements LunchService {

	private List<Order> orders = new ArrayList<Order>(); 

	private RestaurantRepository repo;
	private OrderRepository orderRepo;
	
	public NetCincer(RestaurantRepository repo, OrderRepository orderRepo) {
		this.repo = repo;
		this.orderRepo = orderRepo;
	}
	@Override
	public void order(SimpleOrder order) throws OrderException{
		System.out.println("### new Order:" + order);

		orderRepo.persistSimpleOrder(order);
		orderRepo.listAllOrders();
	}

	private void listOrders() {
		for (Order nextOrder : getOrderHistory()) {
			System.out.println("next Order: " + nextOrder.getPerson());
			for (OrderItem item : nextOrder.getItems()) {
				System.out.println(format ("  %d of %s" , item.getQuantity(), item.getFood()));
			}
		}

	}
	@Override
	public List<Order> getOrderHistory() {
		return orders;
	}

}
